<?php


namespace app\app\controller;


use think\Db;

class Employ extends WxUser
{
    protected $employInfo;
    protected $employId;
    protected $businessInfo;
    protected $businessId;

    protected function initialize()
    {
        parent::initialize();
        //获取员工登录信息
        $employ = Db::name('employ')
            ->where(['member_id' => $this->memberId, 'is_del' => 0])
            ->find();
        if (!$employ) {
            responseJson(-100, '员工信息不存在');
        }
        if ($employ['status'] != 1) {
            responseJson(-200, '员工状态异常，请联系管理员');
        }
        //获取商家信息
        $business = Db::name('business')
            ->where(['id' => $employ['business_id'], 'is_del' => 0])
            ->find();
        if (!$business) {
            responseJson(-100, '商家信息不存在');
        }
        if ($business['status'] != 1) {
            responseJson(-200, '商家状态异常，请联系管理员');
        }
        if (!strpos($business['food_business_license'], 'ttp')) {
            $business['food_business_license'] = config('wechat.url') . $business['food_business_license'];
        }
        if (!strpos($business['business_license'], 'ttp')) {
            $business['business_license'] = config('wechat.url') . $business['business_license'];
        }
        //todo 详细数据
        $business['operate_type_name'] = '独立经营';
        $business['operate_cate_name'] = '饮料/面包';
        $this->businessInfo = $business;
        $this->businessId = $business['id'];
        $this->employInfo = $employ;
        $this->employId = $employ['id'];
    }

    //获取当前员工信息
    public function getEmployInfo()
    {
        msg(0, '查询成功', $this->employInfo);
    }

    /**
     * 获取商家信息
     */
    public function getBusinessInfo()
    {
        msg(0, '查询成功', $this->businessInfo);
    }

    //商家扫码核销 不设置订单失效问题
    public function verifyOrder()
    {
        $data = $this->request->param();
        $order_id = $data['order_id'];
        $result = verifyGoodsOrder($order_id, 1, 2, $this->employId);
        if ($result == -1) {
            msg(-1, '操作有误', $result);
        }
        msg(0, '更新完成', $result);
    }

    //核销码核销
    public function verifyOrderDigits()
    {
        $data = $this->request->param();
        $order_id = $data['order_id'];
        $write_code_digits = $data['write_code_digits'];
        $result = verifyGoodsOrder($order_id, 2, 2, $this->employId, $write_code_digits);
        if ($result == -1) {
            msg(-1, '操作有误', $result);
        }
        msg(0, '更新完成', $result);
    }
}